package com.kzy.demoadmin.web.controller;

import com.github.pagehelper.PageInfo;
import com.kzy.demoadmin.web.entity.Log;
import com.kzy.demoadmin.web.entity.Result;
import com.kzy.demoadmin.web.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 日志管理
 */
@RestController
@RequestMapping("logs")
public class LogController {

    @Autowired
    private LogService logService;

    /**
     * 保存审批
     *
     * @param log
     * @return
     */
    @PostMapping("/save")
    public Result add(@RequestBody Log log) {
        logService.add(log);
        return Result.success();
    }


    /**
     * 分页查询+模糊查询
     *
     * @param log
     * @return
     */
    @GetMapping("/list")
    public Result getBookList(Log log) {
        // 调用服务层分页查询
        PageInfo<Log> info = logService.getLogList(log);
        return Result.success(info);
    }

    /**
     * 根据id删除日志
     */
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        return Result.success(logService.deleteById(id));
    }

    /**
     * 根据id查询日志记录
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id) {
        //待完善

        return Result.success(logService.findById(id));
    }

}
